﻿using System.ComponentModel;
using System.Windows;
using iStudio.Structure.Engine;

namespace iStudio.Structure.Control.Audio.Editor
{
    public abstract class EditorPlugin
    {
        protected AudioEngine SoundPlayer;
        protected EditorCore EditorCore;

        public void RegisterTrackEditor (EditorCore editor)
        {
            EditorCore = editor;

            RegisterTrackEditorEvents ();
            RegisterAudioEngineEvents ();
        }

        public void RegisterSoundPlayer (AudioEngine soundPlayer)
        {
            SoundPlayer = soundPlayer;
            SoundPlayer.PropertyChanged += SoundPlayerPropertyChanged;
        }

        protected virtual void SoundPlayerPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
        }

        public virtual void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            
        }

        protected bool IsEditorCoreInitialized ()
        {
            if ( (EditorCore != null)  && (SoundPlayer != null) )
            {
                if ( (EditorCore.WaveformCanvas != null) && (EditorCore.TimelineCanvas != null) && (EditorCore.ProgressCanvas != null) && (EditorCore.RepeatCanvas != null) )
                {
                    return true;
                }
            }

            return false;
        }

        protected bool HasTracks ()
        {
            if (!IsEditorCoreInitialized())
            {
                return false;
            }

            return (SoundPlayer.Project.TrackList.Count > 0);
        }

        protected abstract void RegisterTrackEditorEvents ();
        protected abstract void RegisterAudioEngineEvents ();
    }
}
